package com.jackrain.clouddata.oms.util;

import org.apache.commons.lang3.time.FastDateFormat;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

/**
 * 时间帮助函数
 * Created by LX on 2017/6/1.
 */
public class DateUtils {

    public final static FastDateFormat dateTimeNumberFormatter = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss");

    public static String getStrNowDate(){
        return dateTimeNumberFormatter.format(new Date());
    }

    public static String getStrDate(Long time){
        return dateTimeNumberFormatter.format(time);
    }
    public static String getYesDayStart(){
        Calendar calendar=Calendar.getInstance();
        calendar.add(Calendar.DATE,-1);//把日期往前减少一天，若想把日期向后推一天则将负数改为正数
        calendar.set(Calendar.HOUR_OF_DAY,0);
        calendar.set(Calendar.MINUTE,0);
        calendar.set(Calendar.SECOND,0);
        return dateTimeNumberFormatter.format(calendar.getTime());
    }

    public static String getYesDayEnd(){
        Calendar calendar=Calendar.getInstance();
        calendar.add(Calendar.DATE,-1);//把日期往前减少一天，若想把日期向后推一天则将负数改为正数
        calendar.set(Calendar.HOUR_OF_DAY,23);
        calendar.set(Calendar.MINUTE,59);
        calendar.set(Calendar.SECOND,59);
        return dateTimeNumberFormatter.format(calendar.getTime());
    }
}
